package com.example.hao.guidancedemo.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.hao.guidancedemo.R;

public class MyViewPageAdapter extends PagerAdapter {
    private Context context;
    private int [] array;

    public MyViewPageAdapter(Context context, int[] array) {
        this.context = context;
        this.array = array;
    }

    @Override
    public int getCount() {
        return array == null? 0:array.length;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_page_item, container, false);
        ImageView iv_show = inflate.findViewById(R.id.iv_show);
        iv_show.setImageResource(array[position]);
        container.addView(inflate);
        return inflate;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }
}
